package 设计模式.状态模式;

public class RaffleActivity {
    //state 标识活动当前的状态，是变化的
    private State state = null;
    //奖品数量
    private Integer count = 0;

    //四个属性，标识四种状态
    State noRaffleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleState(this);
    State dispenseState = new DispenseState(this);
    State dispenseOutState = new DispenseOutState(this);

    //初始化当前的状态为noRaffleState，即不能抽奖状态
    //初始化奖品的数量
    public RaffleActivity(Integer count) {
        this.count = count;
        this.state = getNoRaffleState();
    }

    public void deductMoney() {
        state.deduceMoney();
    }

    public void raffle() {
        //如果当前状态是抽奖成功
        if (state.raffle()) {
            //领取奖品
            state.dispensePrize();
        }
    }

    //注意，每领取一次奖品，count--
    public Integer getCount() {
        int curCount = count;
        count--;
        return curCount;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public State getNoRaffleState() {
        return noRaffleState;
    }

    public void setNoRaffleState(State noRaffleState) {
        this.noRaffleState = noRaffleState;
    }

    public State getCanRaffleState() {
        return canRaffleState;
    }

    public void setCanRaffleState(State canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public State getDispenseOutState() {
        return dispenseOutState;
    }

    public void setDispenseOutState(State dispenseOutState) {
        this.dispenseOutState = dispenseOutState;
    }
}
